package sg.edu.nus.iss.vmcs.maintenance;

/*
 * Copyright 2011 ISS.
 * The contents contained in this document may not be reproduced in any
 * form or by any means, without the written permission of ISS, other
 * than for the purpose for which it has been supplied.
 *
 */

import java.awt.*;
import java.awt.event.*;

/**
 * This class represents the ButtonItem object within {@link ButtonItemDisplay}.
 * This class inherits from the Java AWT Panel class. This button item object
 * represents either a drinks brand or coin denomination depending upon the
 * type. It consists of other components which Button and Label from Java AWT
 * library.
 *
 * @version 1.0  07/12/2011
 * @author Team 7S - SE19
 */

public class ButtonItem extends Panel {

/**
 * Default Length
 */
	public final static int DEFAULT_LEN = 5;

/**
 * Select FLow Layout for Panel 
 */
	public final static int FLOW = 1;

/**
 * Select Grid Layout for Panel 
 */
	
	public final static int GRID = 2;

/**
 * Setting of Color for the Label during clear
 */	
	
	public final static Color DT_COLOR = Color.darkGray;

/**
 * Setting of Color for the Label while active
 */	
	public final static Color ACT_COLOR = Color.white;

	private Button btn;
	private Label value;

/**
 * This constructor creates an instance of the ButtonItem object.
 * @param bn Name of the button (String)
 * @param l  Integer
 * @param lt Type of Layout for setting the Panel
 */	
	public ButtonItem(String bn, int l, int lt) {

		btn = new Button(bn);
		value = new Label("          ");
		value.setBackground(Color.white);

		if (lt == FLOW)
			this.setLayout(new FlowLayout());
		else if (lt == GRID)
			this.setLayout(new GridLayout(1, 2));

		this.add(btn);
		this.add(value);
	}

/**
 * This operation add the action listener to the button object
 * under the ButtonItem. 
 * @param l ActionListener
 */
	
	public void addListener(ActionListener l) {
		btn.addActionListener(l);
	}

/**
 * This operation set the action command to the button object
 * under the ButtonItem. It attaches the specific item (Drink or Coin)
 * to the button.
 * @param cmd String
 */	
	public void setActionCommand(String cmd) {
		btn.setActionCommand(cmd);
	}

/**
 * This operation activates the ButtonItem if the parameter is TRUE. otherwise,
 * the ButtonItem is deactivated.
 * @param st status active or deactive (TRUE / FASLE)
 */	
	public void setActive(boolean st) {
		btn.setEnabled(st);
		value.setEnabled(st);
	}

/**
 * This operation set the background color of the label in ButtonItem.
 * @param cl Color to be set as background
 */
	public void setTextBackground(Color cl) {
		value.setBackground(cl);
	}

/**
 * This operation set the background color of the label on initialize
 */	
	public void clear() {
		setTextBackground(DT_COLOR);
		value.setText("");
	}

/**
 * This operation set the background color of the label on activation
 * and the integer value to be displayed
 * @param vl Integer value to be displayed
 */	
	public void setValue(int vl) {
		String sqt;

		sqt = String.valueOf(vl);
		value.setBackground(ACT_COLOR);
		value.setText(sqt);
	}

/**
 * This operation set the background color of the label on activation
 * and the text to be displayed 
 * @param vl String value to be displayed
 */	
	public void setValue(String vl) {
		value.setBackground(ACT_COLOR);
		value.setText(vl);
	}
}